import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/components/order/group_order_item.dart';
import 'package:cbec_app/components/order/order_item.dart';
import 'package:cbec_app/pages/my/controller/my_group_buy.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/**
 * 我的团购
 */
class MyGroupBuy extends GetView<MyGroupBuyController> {
  MyGroupBuy({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MyGroupBuyController>(builder: (controller) {
      return BasePage(
        title: "我的拼团",
        iconType: IconType.back,
        isShowPadding: true,
        tabHeight: 40.w,
        tabBgColor: Tools.fromHex("#F3F5F7"),
        tabChildren: [_topTabbar()],
        refreshController: controller.baseRefreshCtr,
        enablePullDown: true,
        enablePullUp: controller.hasNextPage,
        onPageLoading: controller.onPageLoading,
        onPageRefresh: controller.onPageRefresh,
        children: [
          Container(
            child: controller.orderList.isNotEmpty
                ? ListView(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    //这里是订单
                    children: List.generate(controller.orderList.length, (index) {
                      final Map item = controller.orderList[index];
                      return GroupOrderItem(
                        orderSn: item['sn'],
                        orderTime: "1212",
                        totalAmount: item['price'],
                        status: item["bookStatus"],
                        goodsList: [
                          {
                            "img": item['img'],
                            "title": item['goodsName'],
                            "num": item["buyNum"],
                            "price": item["price"],
                            "goodsId": item["goodsId"],
                            "tages": ["保税"]
                          }
                        ],
                        id: item["id"],
                        needPeople: item['needPeople'],
                        bookId: item['bookId'],
                      );
                    }))
                : const NotFound(),
          )
        ],
      );
    });
  }

  Widget _topTabbar() => Container(
        margin: EdgeInsets.only(top: 10.w),
        height: 25,
        child: TabBar(
            dividerColor: Colors.transparent,
            indicator: BoxDecoration(
              border: Border(
                bottom: BorderSide(width: 0.8, color: Tools.fromHex("#F83F2D")),
              ),
            ),
            labelColor: Colors.red,
            labelStyle: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: Tools.fromHex("#999999")),
            unselectedLabelColor: Tools.fromHex("#999999"),
            controller: controller.tabController,
            // isScrollable: true,
            // padding: EdgeInsets.zero,
            tabAlignment: TabAlignment.fill,
            tabs: const [
              Tab(
                text: "全部",
              ),
              Tab(
                text: "拼团中",
              ),
              Tab(
                text: "拼团成功",
              ),
              Tab(
                text: "拼团失败",
              ),
            ]),
      );
}
